package com.ruoyi.web.controller.pc;

import com.ruoyi.business.domain.WmsUnit;
import com.ruoyi.business.service.IWmsUnitService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单位Controller
 *
 * @author ruoyi
 * @date 2023-12-31
 */
@RestController
@RequestMapping("/business/unit")
public class WmsUnitController extends BaseController
{
    @Autowired
    private IWmsUnitService wmsUnitService;

    /**
     * 查询单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WmsUnit wmsUnit)
    {
        startPage();
        List<WmsUnit> list = wmsUnitService.selectWmsUnitList(wmsUnit);
        return getDataTable(list);
    }

    @GetMapping("/query")
    public AjaxResult query(WmsUnit wmsUnit)
    {
        List<WmsUnit> list = wmsUnitService.selectWmsUnitList(wmsUnit);
        return AjaxResult.success(list);
    }

    /**
     * 导出单位列表
     */
    @Log(title = "单位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WmsUnit wmsUnit)
    {
        List<WmsUnit> list = wmsUnitService.selectWmsUnitList(wmsUnit);
        ExcelUtil<WmsUnit> util = new ExcelUtil<WmsUnit>(WmsUnit.class);
        return util.exportExcel(list, "单位数据");
    }

    /**
     * 获取单位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wmsUnitService.selectWmsUnitById(id));
    }

    /**
     * 新增单位
     */
    @Log(title = "单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsUnit wmsUnit)
    {
        return toAjax(wmsUnitService.insertWmsUnit(wmsUnit));
    }

    /**
     * 修改单位
     */
    @Log(title = "单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsUnit wmsUnit)
    {
        return toAjax(wmsUnitService.updateWmsUnit(wmsUnit));
    }

    /**
     * 删除单位
     */
    @Log(title = "单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsUnitService.deleteWmsUnitByIds(ids));
    }

    /**
     * 检查名称是否可用
     */
    @PostMapping("checkName")
    public AjaxResult checkName(@RequestBody WmsUnit wmsUnit) {
        return AjaxResult.success(wmsUnitService.checkName(wmsUnit));
    }
}
